home *** CD-ROM | disk | FTP | other *** search
- Path: fiesta.srl.ford.com!usenet
- From: jmccall4@sl0270.srl.ford.com (James McCallum)
- Newsgroups: comp.lang.c++
- Subject: Re: Help! What's wrong with this?
- Date: 18 Apr 1996 15:05:11 GMT
- Organization: SRL, Ford Motor Company
- Distribution: world
- Message-ID: <4l5ln7$sr7@fiesta.srl.ford.com>
- References: <4l22v3$1beo@useneta1.news.prodigy.com>
- Reply-To: jmccall4@sl0270.srl.ford.com
- NNTP-Posting-Host: cae002.srl.ford.com
-
- In article <4l22v3$1beo@useneta1.news.prodigy.com>, NEKU72A@prodigy.com (Brian Munroe) writes:
- >I'm trying to learn C++ and I've run into a strange problem in the
- >following code.
- >
- [main part deleted]
- >
- >void get_customer_info(char temp[ADD_LEN], int flag)
- >{ int answer;
- > int len;
- > clrscr();
- > switch (flag)
- > { case 0:
- > cout << "Enter the bidder's name in one of the following forms.\n";
- > cout << " Person: LAST NAME, FIRST NAME\n";
- > cout << " Business: COMPANY NAME\n\n";
- > break;
- > case 1:
- > cout << "\nEnter first line of address\n";
- > break;
- > case 2:
- > cout << "\nEnter second line of address\n";
- > break;
- > case 3:
- > cout << "\nEnter third line of address\n";
- > break;
- > default:
- > exit(1);
- > }
- > cin >> temp;
- ^^^^^^^^^^^^
- this will throw away any leading white space characters, read the first item in the
- input list up to the first white space characters, and put that in temp. Any
- remaining items in the list will he left for the next read. If your input is like
- Blogs, Joe for the first read, temp will be "Blogs,". The next time you call this
- Function, temp will be "Joe" (and not the first line of the address as desired).
- Try printing out the string after each function call.
- You can get around this by either repeatedly calling cin to get all items in the
- list before returning from the function, or using cin.getline() function to get
- everything up to the next \n in the input stream.
-
- > len = strlen(temp);
- > if (len < ADD_LEN)
- > { strncat(temp, " ",ADD_LEN-
- >len);}
- > temp[ADD_LEN-1] = '\0';
- > return;
- >}
- >
-
-
- Hope this helps.
-
- James
-
- --
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- * *
- * -- James McCallum Ford Motor Company *
- * / / jmccall4@ford.com +1 313 248 9017 *
- * | / *
- * *<%%%%%%%%%%|(===================================-- *
- * | \ *
- * \ \ jmccall4@sl0270.srl.ford.com *
- * -- *
- * *
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
-
-